package cn.edu.scau.cmi.guihao.pane;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.guihao.interProgramming.simpleFactory.InsuranceClaims;
import cn.edu.scau.cmi.guihao.simpleFactory.InsuranceForSimpleFactory;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;

public class SimpleFactoryPane extends Pane implements Initializable {

	@FXML
	private Text name;
	
	@FXML
	private ComboBox<String> selectInsuranceType;
	
	@FXML
	private TextArea displayMessage;
	
	@FXML
	private ImageView photoView;
	
	public SimpleFactoryPane() {
		FXMLLoader loader = new FXMLLoader(getClass().getResource("/cn/edu/scau/cmi/guihao/view/SimpleFactoryView.fxml"));
        loader.setRoot(this);
        loader.setController(this);
        try {
            loader.load();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	
	@FXML
	public void onBtnClick() {
		System.out.println(selectInsuranceType.getValue()+"   "+name.getText());
		InsuranceClaims insurance = InsuranceForSimpleFactory.createInsurance(selectInsuranceType.getValue(),name.getText());
		displayMessage.setText(insurance.compensate());
	}

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		// TODO Auto-generated method stub
		ObservableList<String> type = FXCollections.observableArrayList("身体受伤","汽车损坏","人员伤亡");
		selectInsuranceType.setItems(type);
		Image image = new Image("/cn/edu/scau/cmi/guihao/img/timg.jpg");
		photoView.setImage(image);
	}

	
	
}
